package com.demo.dao;

import com.demo.dto.StageDto;
import com.demo.pojo.Project;
import com.demo.pojo.Stage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName ItemDao
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/25 14:32
 * @Version 1.0
 **/
public interface StageDao {

    //通过pid查询数据
    @Select("select * from stage where pid=#{pid} and status=1")
    List<Stage> findStageByPid(int pid);

    //查询全部数据包括对象的项目名、承包商和开发商
    @Select("select * from stage where  status=1")
    @Results(id = "stageDtoMap",value = {
            @Result(column = "sid",property = "sid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "updateTime",property = "updateTime"),
            @Result(column = "status",property = "status"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "pid",property = "projectDto",javaType = StageDto.class,
                one = @One(select = "com.demo.dao.ProjectDao.findDtoById")
            )
    })
    List<StageDto> findAllDto();

    @Select("select * from stage where sid=#{id} and status=1")
    @ResultMap("stageDtoMap")
    StageDto findOneById(String id);

    @Update("update stage set sname=#{sname},starttime=#{starttime},endtime=#{endtime}," +
            "pid=#{pid},updatetime=#{updatetime} where sid=#{sid}")
    public int updateStage(Stage stage);

    @Update("update stage set status=0 where sid=#{sid}")
    public  int  deleteStageById(String sid);


    //插入数据
    @Insert("insert into stage(sid,sname,starttime,endtime,pid,updatetime) values(#{sid},#{sname},#{starttime},#{endtime},#{pid},#{updatetime})")
    int insertStage(Stage stage);

}
